package com.leo.java8.datetime;

import java.time.LocalDate;
import java.time.temporal.ChronoUnit;
import java.time.temporal.TemporalAdjusters;
import java.time.DayOfWeek;

public class NewFeaturesTester13 {

	public static void main(String args[]) {
		NewFeaturesTester13 tester = new NewFeaturesTester13();
		tester.applyAdjusters();
	}

	public void applyAdjusters() {

		// 获得当前的日期
		LocalDate date1 = LocalDate.now();
		System.out.println("current date: " + date1);

		// 计算下周一的日期并输出
		LocalDate nextMonday = date1.with(TemporalAdjusters.next(DayOfWeek.MONDAY));
		System.out.println("next monday on : " + nextMonday);

		// 获得下个月的第二个周期的日期并输出
		LocalDate date2 = date1.plus(1, ChronoUnit.MONTHS);
		LocalDate firstInMonth = LocalDate.of(date2.getYear(), date2.getMonth(), 1);
		LocalDate secondSunday = firstInMonth.with(TemporalAdjusters.nextOrSame(DayOfWeek.SUNDAY))
				.with(TemporalAdjusters.next(DayOfWeek.SUNDAY));
		System.out.println("second sunday of next month : " + secondSunday);
	}
}